#CFLAGS := -Wall -Werror -O2 -g
CFLAGS := -Wall -O2 -g -fPIC 
CFLAGS += -I $(shell pwd)/include
CFLAGS += -I $(shell pwd)/debug/Dlog

CFLAGS += -I $(TOPDIR)/tools/freetype/include/freetype2
CFLAGS += -I $(TOPDIR)/tools/tslib/include
CFLAGS += -I $(TOPDIR)/tools/jpeg/include
CFLAGS += -I $(TOPDIR)/tools/mqtt/include
CFLAGS += -I $(TOPDIR)/tools/hdf5/include
CFLAGS += -fdiagnostics-color=always
LDFLAGS := -L$(TOPDIR)/tools/freetype/lib -lfreetype
LDFLAGS += -L$(TOPDIR)/tools/zlib/lib -lz
LDFLAGS += -L$(TOPDIR)/tools/png/lib -lpng
LDFLAGS += -L$(TOPDIR)/tools/jpeg/lib -ljpeg
LDFLAGS += -L$(TOPDIR)/tools/tslib/lib -lts
LDFLAGS += -L$(TOPDIR)/tools/mqtt/lib -lpaho-mqtt3c
LDFLAGS += -L$(TOPDIR)/tools/hdf5/lib -lhdf5


LDFLAGS += -lm -lpthread

export CFLAGS LDFLAGS

NOWDIR := $(shell pwd)
export NOWDIR

TARGET := digitpic
LIBTARGET := libsetting.so
LIBOBJS := ./setting/pub_lib.o 

obj-y := main.o
obj-y += debug/
obj-y += display/
obj-y += encoding/
obj-y += file/
obj-y += fonts/
obj-y += input/
obj-y += page/
obj-y += render/
obj-y += video/
obj-y += mqtt/
obj-y += cnn/
obj-y += setting/

all : start_recursive_build $(TARGET) $(LIBTARGET) test
	@echo $(TARGET) has been built!

start_recursive_build:
	make -C ./ -f $(NOWDIR)/Makefile.build

$(TARGET) : start_recursive_build
	$(Q)$(CC) -o $(TARGET) built-in.o $(LDFLAGS)

$(LIBTARGET) : $(LIBOBJS)
	$(CC) -shared -o $@ $^

test:
	make -C ./setting/test

install:
	install -d $(rootfsdir)
	install -m 755 $(TARGET) $(rootfsdir)

clean:
	rm -f $(shell find . -name "*.o")
	rm -f $(TARGET)
	rm -f $(shell find . -name "*.so")

distclean:
	rm -f $(shell find . -name "*.o")
	rm -f $(shell find . -name "*.o.d")
	rm -f $(shell find . -name "*.so")
	rm -f $(TARGET)
	
